package com.example.demo.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.entity.Book;
import com.example.demo.service.BookService;

@Controller
@RequestMapping("book")
public class BookController {
	
	@Resource
	private BookService bookService;

	@GetMapping("add")
	public String insertBookView() {
		return "book/insert";
	}
	
	@PostMapping("insert")
	@ResponseBody
	public Object insertBook(Book book) {
		Book book2 = bookService.insertBook(book);
		return book2;
	}
	
	@GetMapping("one")
	@ResponseBody
	public Object getBook() {
		return bookService.getById(1);
	}
	@GetMapping("all")
	@ResponseBody
	public Object getBookALl() {
		return bookService.getAll();
	}
	
	@GetMapping("by_name")
	@ResponseBody
	public Object getByName(String name)
	{
		return bookService.getByName(name);
	}
}
